<!--
 * @Description: 培训学员登记表
 * @Autor: dyx
 * @Date: 2023-05-30 14:36:16
 * @LastEditTime: 2023-05-31 15:26:36
-->
<template>
  <div class="TISchedule">
    <div style="padding-right: 7px;">
      <el-button type="primary" style="float:right" @click="exportWord">导出Word</el-button>
    </div>
    <div class="mytable" v-loading="loading">
      <div class="table_title">培训学员登记表</div>
      <table>
        <tr>
          <td width="10%">
            姓名
          </td>
          <td width="10%"></td>
          <td width="8%">
            性别
          </td>
          <td width="8%"></td>
          <td width="17%">
            联系电话
          </td>
          <td width="17%"></td>
          <td rowspan="5">
            1 寸 照片
          </td>
        </tr>
        <tr>
          <td>
            曾用名
          </td>
          <td></td>
          <td>
            民族
          </td>
          <td></td>
          <td>
            身份证号
          </td>
          <td></td>
        </tr>
        <tr>
          <td>
            政治面貌
          </td>
          <td colspan="3"></td>
          <td>
            从事岗位
          </td>
          <td></td>
        </tr>

        <tr>
          <td>
            人员类别
          </td>
          <td colspan="5">
            <el-radio-group v-model="radio">
              <el-radio :label="1">高危行业主要负责人</el-radio>
              <el-radio :label="2">高危行业安管人员</el-radio>
              <el-radio :label="3">特种作业人员</el-radio>
              <el-radio :label="4">一般行业主要负责人</el-radio>
              <el-radio :label="5">一般行业安管人员</el-radio>
              <el-radio :label="6">其他从业人员</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td>
            单位名称
          </td>
          <td colspan="5"></td>
        </tr>
        <tr>
          <td>
            学历
          </td>
          <td></td>
          <td>
            所学专业
          </td>
          <td></td>
          <td>
            职务/职称
          </td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td>
            培训类别
          </td>
          <td colspan="5">
            <el-radio-group v-model="radio">
              <el-radio :label="3">初训</el-radio>
              <el-radio :label="6">复训</el-radio>
              <el-radio :label="9">换证</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td>
            详细地址
          </td>
          <td colspan="6" style="text-align: center;" valign="middle"></td>
        </tr>
        <tr height="445px">
          <td>
            工作经历
          </td>
          <td colspan="6" style="text-align: center;" valign="middle"></td>
        </tr>
        <tr height="245px">
          <td>
            单位审核意见
          </td>
          <td colspan="5"></td>
          <td>
            照片轻粘处 (1 寸彩色)
          </td>
        </tr>
      </table>

      <div class="table_bottom">注：身份证复印件粘贴在本表背面。</div>
    </div>
  </div>
</template>
<script>
import request from "@/utils/request";
export default {
  name: "TISchedule",
  data() {
    return {
      loading: true,
      dataForm: {},
      list: [],
      radio: 3
    };
  },
  created() { },
  methods: {
    init(id) {
      this.loading = true;
      console.log(id, 1234)
      request({
        url: "/api/class_archives/generateA1/" + id + `?organizeId=${this.$store.getters.organizeId}`,
        method: "get"
      }).then(res => {
        console.log(res, 123);
        this.dataForm = res.data;
        // 创建10位数组
        this.list = Array.apply(null, { length: 10 }).map(() => {
          return { xh: "", kcmc: "", xs: "", ckjc: "", xm: "", xl: "", zw: "" };
        });
        // 获取数据数组长度
        let lgh = this.dataForm.childrenVOList.length;
        // 替换数组
        this.list.splice(0, lgh, ...this.dataForm.childrenVOList);
        this.loading = false;
        console.log(this.loading, 111)
      });
    },
    exportWord() {
      this.dataForm.childrenVOList = this.list;
      for (let key in this.dataForm) {
        if (Array.isArray(this.dataForm[key])) {
          if (key == "childrenVOList") {
            this.dataForm[key].forEach(item => {
              for (let key2 in item) {
                if (item[key2] == null) {
                  item[key2] = "";
                }
              }
            });
          } else {
            this.dataForm[key] = this.dataForm[key].join(",");
          }
        } else if (this.dataForm[key] == null) {
          this.dataForm[key] = "";
        }
      }
      this.dataForm.organizeId = this.$store.getters.organizeId;
      request({
        responseType: "blob",
        url: "/api/class_archives/generateA1Export",
        method: "post",
        data: this.dataForm
      }).then(res => {
        // console.log(res, 123);
        var debug = res;
        if (debug) {
          var a = document.createElement("a");
          a.download = "培训学员登记表.docx";
          a.style.display = "none";
          var blob = new Blob([debug], { type: "application/x-msdownload" });
          a.href = URL.createObjectURL(blob);
          document.body.appendChild(a);
          a.click();
          document.body.removeChild(a);
        }
      });
    }
  }
};
</script>
<style scoped lang="scss">
// 引入公共样式
@import "./TABLESTYLE.scss";
</style>
